package com.jf3q.security.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jf3q.security.entity.EduAclRole;
import com.jf3q.security.entity.EduAclUser;
import com.jf3q.security.mapper.EduAclUserMapper;
import com.jf3q.security.service.EduAclUserService;
import jakarta.annotation.Resource;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 *
 */
@Service
public class EduAclUserServiceImpl extends ServiceImpl<EduAclUserMapper, EduAclUser>
    implements EduAclUserService, UserDetailsService {
    @Resource
    EduAclUserMapper userMapper;

    @Override
    public EduAclUser loadUserByUsername(String username) throws UsernameNotFoundException {

        LambdaQueryWrapper<EduAclUser> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EduAclUser::getUsername, username);
        EduAclUser user = this.getOne(queryWrapper);
        if (user == null) {
            throw new UsernameNotFoundException("用户名不存在！");
        }
        List<EduAclRole> roleList = userMapper.getByUserId(user.getId());
        user.setRoles(roleList);
        return user;
    }
}




